#include <iostream>
#include <cstdio>
#include <vector> 
#include <algorithm>

using namespace std; 

struct student_t {
	int id; 
	string name; 
	int score; 
	int c_score; 
	char cadre; 
	char western; 
	int essay; 
	int ss; //scholarship
}; 

bool cmp_w(student_t &a, student_t &b)
{
	return (a.ss==b.ss) ? (a.id<b.id) : (a.ss>b.ss); 
}

int main()
{
	int i, n; 
	vector <student_t> sd; 
	student_t s; 
	int total = 0; 
	
	//freopen("p1058_1.in", "r", stdin); 
	
	cin>>n; 
	for (i=0; i<n; i++) {
		s.id = i; 
		cin>>s.name>>s.score>>s.c_score>>s.cadre>>s.western>>s.essay; 
		s.ss = 0; 
		if (s.score>80 && s.essay>=1) {
			s.ss += 8000; 
		}
		if (s.score>85 && s.c_score>80) {
			s.ss += 4000; 
		}
		if (s.score>90) {
			s.ss += 2000; 
		}
		if (s.score>85 && s.western=='Y') {
			s.ss += 1000; 
		}
		if (s.c_score>80 && s.cadre=='Y') {
			s.ss += 850; 
		}
		total += s.ss; 
		sd.push_back(s); 
	}
	
	sort(sd.begin(), sd.end(), cmp_w); 
	
	cout<<sd[0].name<<"\n"; 
	cout<<sd[0].ss<<"\n"; 
	cout<<total<<"\n"; 
	return 0; 
}


